package com.magina.common.bean2xml;

import com.google.common.collect.Maps;
import com.magina.common.constant.DateFormatUtil;
import com.magina.common.exception.BusinessException;
import org.assertj.core.util.Lists;

import java.util.Date;
import java.util.List;
import java.util.Map;

//https://blog.csdn.net/hnzmdpan/article/details/84896296
public class Xml2StringTest {
    public static void main(String[] args) throws BusinessException {
        List<FatherXmlModel> userInfoList = Lists.newArrayList();
        List<FatherModel> userList = Lists.newArrayList();
        for (int i = 0; i < 3; i++) {
            FatherXmlModel son = new SonXmlModel();
           ((SonXmlModel) son).setSonName("sonName第" + i + "次");
           son.setFatherXmlProp1("extendProp" + i);
           ((SonXmlModel) son).setSonAge(i);
            userInfoList.add(son);

            FatherModel son1 = new SonModel();
            ((SonModel) son1).setSonPropOne("2sonName第" + i + "次");
            son1.setFatherPropOne("extendProp" + i);
            ((SonModel) son1).setSonPropTwo(i+"");
            userList.add(son1);
        }
        // 创建需要转换的对象
        User sonUser = new User(1, "Steven", "@sun123", new Date(),
                1000.0,userInfoList,userList);


        UserInfo sonUserInfo =new UserInfo();
        sonUserInfo.setUser(sonUser);
        String str = JaxbUtil.convertToXml(sonUserInfo);
        System.out.println(str);
        List<FatherXmlModel> daughterList = Lists.newArrayList();
        List<FatherModel> daughterUserList =Lists.newArrayList();
        for (int i = 0; i < 3; i++) {
            FatherXmlModel daughter = new DaughterXmlModel();
            ((DaughterXmlModel) daughter).setDaughterName("daughtName" + i + "次");
            daughter.setFatherXmlProp1("extendProp" + i);
            ((DaughterXmlModel) daughter).setDaughterAge(i);
            daughterList.add(daughter);

            FatherModel daughter1 = new DaughterModel();
            ((DaughterModel) daughter1).setDauProOne("daughtName" + i + "次");
            daughter1.setFatherPropOne("extendProp" + i);
            ((DaughterModel) daughter1).setDauProTwo(i+"");
            ((DaughterModel) daughter1).setDauDateOne(new Date());
            ((DaughterModel) daughter1).setDauDateTwo(DateFormatUtil.Str2DateStr(new Date()));
            Map map = Maps.newConcurrentMap();
            map.put(i, "this is " + i + " test!");
            map.put(i+10, "this is " + i+10 + " test!");
            ((DaughterModel) daughter1).setDauMap(map);
            daughterUserList.add(daughter1);
        }
        // 创建需要转换的对象
        User daughterUser = new User(2, "daughter", "@daughter123", new Date(),
                1000.0,daughterList,daughterUserList);
        UserInfo daughterUserInfo =new UserInfo();
        daughterUserInfo.setUser(sonUser);
        String dauthterStr = JaxbUtil.convertToXml(daughterUser);
        System.out.println(dauthterStr);




//        String path = "E:\\user.xml";
//        System.out.println("---将对象转换成File类型的xml Start---");
//        JaxbUtil.convertToXml(user, path);
//        System.out.println("---将对象转换成File类型的xml End---");
//        System.out.println();
//        System.out.println("---将File类型的xml转换成对象 Start---");
//        User user2 = (User) JaxbUtil.convertXmlFileToObject(User.class, path);
//        System.out.println(user2);
//        System.out.println("---将File类型的xml转换成对象 End---");

//        ExcelReader excelReader = ExcelUtil.getReader("C:\\Users\\Administrator\\Desktop\\楼栋供应计划20190408212707.xls");
//        List<List<Object>>  list = excelReader.read(1);

    }

}
